﻿using RabbitMQSDK;

namespace DDDDemo2;

public class RabbitMQAuditMessageSenderProvider : IAuditMessageSenderProvider
{
    private readonly RabbitMQTemplate<string, string> _RabbitMQTemplate;

    public const string ProviderName = "RabbitMQ";

    private const string TOPIC_AUDIT_LOG = "topic_audit_log";

    public string Name => ProviderName;

    public RabbitMQAuditMessageSenderProvider(RabbitMQTemplate<string, string> rabbitMQTemplate)
    {
        _RabbitMQTemplate = rabbitMQTemplate;
    }

    public async Task<TransferAuditMessageSendStatus> SendAsync(TransferAuditMessage message)
    {
        var messageText = ParseToMessageText(message);
        await _RabbitMQTemplate.SendAsync(TOPIC_AUDIT_LOG, messageText);
        return TransferAuditMessageSendStatus.Success;
    }

    private static string ParseToMessageText(TransferAuditMessage message)
    {
        return $"RabbitMQ message:{message.UserId},{message.MerchantAccountNo},{message.Amount}";
    }
}
